package io.bdmc.modules.bss.service.impl;

import io.bdmc.common.enums.RouteTypeEnum;
import io.bdmc.common.utils.MyPage;
import io.bdmc.modules.bss.entity.DeviceRoute;
import io.bdmc.modules.bss.mapper.DeviceRouteMapper;
import io.bdmc.modules.bss.service.IDeviceFibreMatchService;
import io.bdmc.modules.bss.service.IDeviceRouteService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 路由 服务实现类
 * </p>
 *
 * @author 黄露
 * @since 2021-05-21
 */
@Service
public class DeviceRouteServiceImpl extends ServiceImpl<DeviceRouteMapper, DeviceRoute> implements IDeviceRouteService {
    @Autowired
    DeviceRouteMapper _devicerouteMapper;

    @Autowired
    IDeviceFibreMatchService matchService;

    @Override
    public MyPage<DeviceRoute> mySelectPage(MyPage<DeviceRoute> myPage) {
        return _devicerouteMapper.mySelectPage(myPage);
    }

    @Transactional
    @Override
    public Boolean deleteRoute(DeviceRoute route) {
        final RouteTypeEnum routeTypeEnum = RouteTypeEnum.valueOf(route.getRouteType());
        switch(routeTypeEnum){
            case fspRoute:
                matchService.unbindDeviceBySn(route.getDeviceSnFrom());
                matchService.unbindDeviceBySn(route.getDeviceSnTo());
                break;
            case realTimeRoute:
                matchService.unbindDeviceBySn(route.getFmsSn());
                break;
            case pollingRoute:
                matchService.unbindDeviceBySn(route.getFmsSn());
                matchService.unbindDeviceBySn(route.getOswSn());
                break;
            case offlineRoute:
                matchService.unbindDeviceBySn(route.getFmsSn());
                matchService.unbindDeviceBySn(route.getOswSn());
                matchService.unbindDeviceBySn(route.getOpmSn());
                break;
            default:
                break;
        }
        removeById(route.getRouteId());
        return true;
    }
}
